package com.kuizii.demo.core.service;

import com.kuizii.base.common.utils.BeanHelper;
import com.kuizii.demo.api.UserService;
import com.kuizii.demo.core.data.service.SysUserDataService;
import com.kuizii.demo.core.domain.entity.user.SysUserEntity;
import com.kuizii.demo.domain.SysUserDto;
import io.swagger.annotations.Api;
import org.apache.dubbo.apidocs.annotations.ApiDoc;
import org.apache.dubbo.apidocs.annotations.ApiModule;
import org.apache.dubbo.apidocs.core.providers.IDubboDocProvider;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;

/**
 * <p>
 * 如果业务微复杂 ,由Service层聚合dataService层以及manager层的数据,提供服务
 * <p/>
 *
 * @author nuanyang
 * Email freexiaodong@163.com
 * Created by 2019-06-16 16:32:52
 */

@Api(value = "用户表接口文档")
@ApiModule(value = "测试接口服务", apiInterface = UserService.class)
@DubboService(version = "1.0",group = "demo")
public class UserServiceImpl implements UserService {


    @Autowired
    SysUserDataService sysUserDataService;

    //调用manager层
    //@Autowired
    //XXManager xxManager;

    @ApiDoc(value = "测试查询接口",  description = "通过id查用户", responseClassDescription = "返回用户DTO")
    @Override
    public SysUserDto getUserById(String userId) {

        SysUserEntity entity = sysUserDataService.getById(userId);
        SysUserDto result = BeanHelper.copyProperties(entity, SysUserDto::new);
        return result;
    }

    @ApiDoc(value = "测试保存接口",  description = "保存新用户", responseClassDescription = "无需返回")
    @Override
    public void addUser(@Valid SysUserDto dto) {
        SysUserEntity result = BeanHelper.copyProperties(dto, SysUserEntity::new);
        sysUserDataService.saveOrUpdate(result);
    }

}
